<?php
  require_once('includes/db.php');
  if(isset($_SESSION['id'])) {
    header('location:all_users.php');
    exit;
  }
  
  pr($_POST);
  pr1($_COOKIE);
  if(isset($_POST['email']) && isset($_POST['password'])) {
    if(!empty($_POST['email']) && !empty($_POST['password'])) {
        $email = mysql_real_escape_string(trim($_POST['email']));
        $password = md5(mysql_real_escape_string(trim($_POST['password'])));
        $where = "`email`='$email' AND `password`='$password' AND `status`='1'";
        $userResult = fetchAll('admin',$where);
        $user = mysql_fetch_assoc($userResult);
        if(isset($user['id'])) {

          $_SESSION['id'] = $user['id'];
          $_SESSION['name'] = $user['name'];
          $_SESSION['email'] = $user['email'];
          #########################################
          $time = (isset($_POST['remember']))? time()+1*60:time()-1;
          setcookie('email',$_POST['email'],$time);
          setcookie('password',$_POST['password'],$time);
          #########################################
          
          header("location:all_users.php");
          exit;
        }
pr($user);
    } else {
      echo "Email / password missing..";
    }
  }

?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Signin Template for Bootstrap</title>
    <!-- Bootstrap core CSS -->
    <link href="dist/css/bootstrap.css" rel="stylesheet">
    <!-- Custom styles for this template -->
    <link href="css/signin.css" rel="stylesheet">
  </head>
  <body>
    <div class="container">
      <form class="form-signin" method="post" action="" role="form">
        <h2 class="form-signin-heading">Please sign in</h2>
        <input value="<?=@$_COOKIE['email']?>" type="text" name="email" class="form-control" placeholder="Email address" required autofocus>
        <input value="<?=@$_COOKIE['password']?>" type="password" name="password" class="form-control" placeholder="Password" required>
        <label class="checkbox">
          <input type="checkbox" checked name="remember" > Remember me
        </label>
        <input value="Sign in" class="btn btn-lg btn-primary btn-block" type="submit">
      </form>
<a href="register.php">register</a>
<h4>admin@gmail.com' OR '1'='1</h4>
<?php  require_once('includes/footer.php'); ?>
